//获取webpack 配置
const reslove = require('reslove')
const path = require('path')
const fs = require('fs')
const execa = require('execa')

module.exports = function (paths, args) {
    const cwd = process.cwd();//获取当前目录
    let servicePath = reslove.sync('@vue/cli-service', { basdedir: cwd });
    const binPath = path.reslove(servicePath, '../../bin/vue-cli-service.js');
    if (fs.existsSync(binPath)) {
        execa(
            'node',
            [binPath,
                'inspect',
                ...(args.mode ? ['--mode', args.mode] : []),
                ...(args.rule ? ['--rule', args.rule] : []),
                ...(args.plugin ? ['--plugin', args.plugin] : []),
                ...(args.rules ? ['--rules'] : []),
                ...(args.plugins ? ['--plugins'] : []),
                ...(args.verbose ? ['--verbose'] : []),
                ...paths
            ],
            { cwd, stdio: 'inherit' });//调用cli-service 模块的功能。
    }
}